const { contextBridge, ipcRenderer } = require('electron')

contextBridge.exposeInMainWorld('preloadApi', {
  setTheme: (theme) => {
    ipcRenderer.invoke('setTheme', theme)
  },
})

document.addEventListener('DOMContentLoaded', () => {
  const updateTheme = (theme) => (isDarkMode.textContent = theme === 'dark' ? '是的' : '不是')
  ipcRenderer.on('themeChanged', (_, theme) => updateTheme(theme))
  ipcRenderer.invoke('isDarkMode').then(updateTheme)
})
